package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.EmailIdentityBean;
import com.yiwei.zhh.api.callback.EmailContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class EmailRequest extends BaseRequest<EmailContract.View> implements EmailContract.Presenter<EmailContract.View> {

    public static EmailRequest create() {
        return new EmailRequest();
    }


    @Override
    public void getEmail(String email, String action) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        EmailIdentityBean bean = new EmailIdentityBean();
        bean.action = action;
        bean.email = email;
        Api.api_service.getEmailIdentity(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getEmailSuccess(result);
                });
    }

}
